package com.ruoyi.flow.common.tools.mediaconverter.converter.converter;



import com.ruoyi.flow.common.tools.mediaconverter.converter.ffmpeg.FfmpegInvoker;
import com.ruoyi.flow.common.tools.mediaconverter.converter.ffmpeg.FfmpegLocator;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/7/14.
 */
public abstract class IConverter {

    protected String srcFilePath;
    protected String destFilePath;

    public IConverter(String srcFilePath, String destFilePath) {
        checkNotNull(srcFilePath);
        checkNotNull(destFilePath);
        this.srcFilePath = srcFilePath;
        this.destFilePath = destFilePath;
    }

    private FfmpegInvoker createInvoker(String cmdDirOnWindows, String cmdDirOnLinux) {
    	FfmpegLocator locator = FfmpegLocator.getLocator(cmdDirOnWindows, cmdDirOnLinux);
    	return createInvoker(locator);
    }

    /**
     *
     * @param cmdDirOnWindows
     * @param cmdDirOnLinux
     * @param timeout
     */
    public void invoke(String cmdDirOnWindows,String cmdDirOnLinux,long timeout) {
    	checkNotNull(cmdDirOnWindows);
    	FfmpegInvoker invoker = createInvoker(cmdDirOnWindows, cmdDirOnLinux).timeout(timeout);
    	invoker.invoke();
    }
    
    protected abstract FfmpegInvoker createInvoker(FfmpegLocator locator);
}
